package it.univaq.mwt.common.startup;

import it.univaq.mwt.common.business.CategoryServiceFactory;
import it.univaq.mwt.common.business.ServicesServiceFactory;
import it.univaq.mwt.common.business.UsersServiceFactory;
import it.univaq.mwt.common.business.impl.DBCategoryServiceFactory;
import it.univaq.mwt.common.business.impl.DBGiftServiceFactory;
import it.univaq.mwt.common.business.impl.DBGroupsServiceFactory;
import it.univaq.mwt.common.business.impl.DBListServiceFactory;
import it.univaq.mwt.common.business.impl.DBNewsServiceFactory;
import it.univaq.mwt.common.business.impl.DBServicesServiceFactory;
import it.univaq.mwt.common.business.impl.DBUsersServiceFactory;
import it.univaq.mwt.common.business.impl.DBFilesServiceFactory;
import it.univaq.mwt.model.bean.CategoryBeanRemote;
import it.univaq.mwt.model.bean.FilesBeanRemote;
import it.univaq.mwt.model.bean.GiftBeanRemote;
import it.univaq.mwt.model.bean.GroupsBeanRemote;
import it.univaq.mwt.model.bean.ListBeanRemote;
import it.univaq.mwt.model.bean.NewsBeanRemote;
import it.univaq.mwt.model.bean.ServicesBeanRemote;
import it.univaq.mwt.model.bean.UsersBeanRemote;


import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;



public class WishlistrServletContextListener implements ServletContextListener {

	public void contextInitialized(ServletContextEvent event) {
		try {
			
			CategoryBeanRemote cbr = ((CategoryBeanRemote)new InitialContext().lookup("CategoryBean/remote"));
			CategoryServiceFactory.setInstance(new DBCategoryServiceFactory(cbr));
			System.out.println("CategoryBean lookup created");

			FilesBeanRemote fbr = ((FilesBeanRemote)new InitialContext().lookup("FilesBean/remote"));
			DBFilesServiceFactory.setInstance(new DBFilesServiceFactory(fbr));
			System.out.println("FilesyBean lookup created");
			
			GiftBeanRemote gbr = ((GiftBeanRemote)new InitialContext().lookup("GiftBean/remote"));
			DBGiftServiceFactory.setInstance(new DBGiftServiceFactory(gbr));
			System.out.println("GiftBean lookup created");
			
			GroupsBeanRemote grbr = ((GroupsBeanRemote)new InitialContext().lookup("GroupsBean/remote"));
			DBGroupsServiceFactory.setInstance(new DBGroupsServiceFactory(grbr));
			System.out.println("GroupsBean lookup created");
			
			
			ListBeanRemote lbr = ((ListBeanRemote)new InitialContext().lookup("ListBean/remote"));
			DBListServiceFactory.setInstance(new DBListServiceFactory(lbr));
			System.out.println("ListBean lookup created");
			
			
			NewsBeanRemote nbr = ((NewsBeanRemote)new InitialContext().lookup("NewsBean/remote"));
			DBNewsServiceFactory.setInstance(new DBNewsServiceFactory(nbr));
			System.out.println("NewsBean lookup created");
			

			ServicesBeanRemote sbr = ((ServicesBeanRemote)new InitialContext().lookup("ServicesBean/remote"));
			ServicesServiceFactory.setInstance(new DBServicesServiceFactory(sbr));
			System.out.println("ServicesBean lookup created");
			

			UsersBeanRemote ubr = ((UsersBeanRemote)new InitialContext().lookup("UsersBean/remote"));
			UsersServiceFactory.setInstance(new DBUsersServiceFactory(ubr));
			System.out.println("UsersBean lookup created");
			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void contextDestroyed(ServletContextEvent event) {
		// TODO Auto-generated method stub
		
	}


}
